<template>
	<view class="content">
		<scroll-view class="type-left" :scroll-y="true">
			<view :class="i == typeIndex?'newtype':''" class="type-item" v-for="(item,i) in typeList" :key="i"
				@click="typeClcik(item,i)">
				<view class="type-name">{{ item.name }}</view>
				<view class="type-block" v-if="i == typeIndex">

				</view>
			</view>
		</scroll-view>
		<scroll-view class="type-right" :scroll-y="true">
			<view class="shop" v-for="(list,i) in shopList" :key="i">
				<view class="shop-title" v-if="list.name">
					{{ list.name }}
				</view>
				<view class="shop-list">
					<block v-if="list.shop.length">
						<view class="list" v-for="(item,index) in list.shop" :key="index" @tap="GoDetails(item)">
							<view class="list-img">
								<image style="border-radius: 12rpx;" :src="tool.img(item.zhuimages[0])" mode="aspectFill">
								</image>
							</view>
							<view class="list-name">
								<view class="p-name">
									{{ item.name }}
								</view>
								<view class="p-content">
									<view class="p-price">
										<text>￥</text>
										<text>268</text>
									</view>
									<view class="p-num">
										<text>已售1578</text>
									</view>
								</view>
								<view class="p-footer">
									<view class="p-left">
										<text>7天无理由退货</text>
									</view>
									<view class="p-right">
										<text>运费险</text>
									</view>
								</view>
							</view>
						</view>
					</block>
					<block v-else>
						<view style="text-align: center;font-size: 28rpx;color: #999;width: 100%;margin-top: 80rpx;">暂无商品</view>
					</block>
				</view>
			</view>

		</scroll-view>
	</view>
</template>

<script>
	import tool from '../../utils/tool.js'
	export default {
		data() {
			return {
				tool: tool,
				typeIndex: 0,
				page: 1,
				typeList: [],
				pid: '', //二级分类ID
				shopList: [],
				config:''
			}
		},
		onLoad() {
			this.GetTypeOne()
		},
		methods: {
			
			GoDetails(item) {
				uni.navigateTo({
					url: '/pages/book/index?id=' + item.id
				})
			},
			GetTypeOne() { //获取一级分类
				this.$http.Post('zter/typeList', {
					pid: 0
				}, (result) => {
					this.typeList = result.data
					this.pid = this.typeList[0].id
					this.GetList()
				})
			},
			GetList() { //获取商品
				this.$http.Post('zter/typeShopList', {
					pid: this.pid
				}, (result) => {
					console.log(result.data.erji)
					this.shopList = result.data.erji
				})
			},
			typeClcik(item, i) {
				this.page = 1
				this.pid = item.id
				this.typeIndex = i
				this.GetList() //切换二级分类
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
	}

	.type-left {
		width: 30%;
		height: 100vh;
		background-color: #f6f6f6;
		font-size: 28rpx;
		position: relative;
	}

	.type-block {
		position: absolute;
		width: 10rpx;
		height: 100rpx;
		background-color: #fc6564;
		left: 0;
	}

	.newtype {
		background-color: #fff;
		font-weight: bold;
	}

	.type-item {
		width: 100%;
		height: 120rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.type-name {
		width: 80%;
		height: 100%;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.type-right {
		width: 70%;
		height: 100vh;
		background-color: #fff;
	}

	.shop-title {
		font-size: 30rpx;
		font-weight: bold;
		padding: 30rpx 35rpx;

	}

	.shop-list {
		padding: 0 10rpx;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.list {
		width: 100%;
		margin: 20rpx 0 20rpx 20rpx;
		display: flex;
	}

	.list-img {
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.list-img>image {
		width: 200rpx;
		height: 155rpx;
	}

	.list-name {
		padding-left: 2%;
		width: 98%;
		
	}

	.p-name {
		font-weight: bold;
		color: #333;
		font-size: 28rpx;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.p-content {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 10rpx;
	}

	.p-price {
		font-weight: bold;
		color: #ff5502;
		font-size: 28rpx;
	}

	.p-num {
		font-size: 26rpx;
		color: #ccc;
	}

	.p-footer {
		margin-top: 10rpx;
		width: 100%;
		display: flex;
		font-size: 24rpx;
		align-items: center;
		color: #deab80;
	}


	.p-left {
		background-color: #fff1ee;
		margin-right: 10rpx;
		border: 1rpx solid #deab80;
		padding: 2rpx 4rpx;
		border-radius: 4rpx;
	}

	.p-right {
		border-radius: 4rpx;
		padding: 2rpx 4rpx;
		border: 1rpx solid #deab80;
		background-color: #fff1ee;
	}
</style>